<?php
/**
 * Created by PhpStorm.
 * User: jdong
 * Date: 16/3/6
 * Time: 上午9:06
 */

namespace Home\Controller;
use Think\Controller;
use Think\Log;

use Common\Controller\AuthController;

class LoginController extends AuthController
{

    public function index()
    {
        Log::Record("LoginController_index","DEBUG");

        if (IS_POST) {
            $login = array();
            switch (I('user', null, false)) {
                case 'admin' :
                    $login['uid'] = 1;
                    $login['user'] = 'admin';
                    break;
                case 'test' :
                    $login['uid'] = 2;
                    $login['user'] = 'test';
                    break;
                case 'guest' :
                    $login['uid'] = 3;
                    $login['user'] = 'guest';
                    break;
                default:
                    $this->error('登录的用户不存在！');


            }

        }


        if (count($login)) {
            session('auth', $login);
            $this->success('登录成功！', U('Index/index'));

        } else {
            $this->display();
        }


    }

    public function logout()
    {
        session('[destroy]');
        $this->success('退出成功！', U('Login/index'));
    }

}